package com.ymatou.iapi.selleraccount.testcase;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.selleraccount.service.UpdateSellerSubAccountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.YmtSellerSubAccountRelated;
import com.ymttest.database.sqlwapper.YmtSellerSubAccountRelatedIMapper;

/**
 * @serial 2016-12-25
 * @author chencan
 * 修改子账号信息接口
 */
public class Tc_UpdateSellerSubAccount {
	private static UpdateSellerSubAccountCall getUpdateSellerSubAccountCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("业务说明：修改子账号");
	}

	@Before
	public void caseUp() {
		getUpdateSellerSubAccountCall = new UpdateSellerSubAccountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getUpdateSellerSubAccountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateSellerSubAccount_001(){
		Logger.start(true, "子账号修改");
		try {
			
			int sellerId=3383;
			//int sellerSubAccountUserid = 20326245;
			String password ="1234qwer`";
			String remark ="子账号备注";
			String phone ="555555";
			String country = "美国";
			int countryPhoneCode = 1; //区号可以等于注册国和中国
			JSONArray roleidlist = new JSONArray();
			roleidlist.put(8).put(9);
			
			List<YmtSellerSubAccountRelated> accounts = new YmtSellerSubAccountRelatedIMapper().selectSubAccountRelatedSellerIds(sellerId);
			YmtSellerSubAccountRelated firsts =accounts.get(0);
			int sellerSubAccountUserid = firsts.getSubsellerUserid();
			
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("SellerId",sellerId);
			map1.put("SellerSubAccountUserid",sellerSubAccountUserid);
			map1.put("Password",password);
			map1.put("Remark",remark);
			map1.put("Country",country);
			map1.put("Phone",phone);
			map1.put("CountryPhoneCode",countryPhoneCode);
			map1.put("RoleidList",roleidlist);
			
			JSONObject create = new UpdateSellerSubAccountCall().callAndGetReturnData(map1);
			int retBea = create.getInt("Code");
			boolean success = create.getJSONObject("Data").getBoolean("Success");
			
			List<YmtSellerSubAccountRelated> account = new YmtSellerSubAccountRelatedIMapper().selectSubAccountRelatedSubsellerUserid(sellerSubAccountUserid);
			YmtSellerSubAccountRelated first =account.get(0);
			String remarks = first.getRemark();
			int countryPhone = first.getSubSellerCountryPhoneCode();
			String countrys = first.getCountry();
			String phones = first.getSubSellerPhone();
			
			Logger.verifyEquals(200, retBea, "返回结果等于200");
			Logger.verifyEquals(true, success, "返回状态");
			Logger.verifyEquals(remark, remarks, "子账号备注信息");
			Logger.verifyEquals(countryPhoneCode, countryPhone, "所属国");
			Logger.verifyEquals(country, countrys, "国家名称");
			Logger.verifyEquals(phone, phones, "手机号");

		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateSellerSubAccount_002(){
		Logger.start(true, "子账号修改 -- 密码不符合要求");
		try {
			
			String password ="1234";
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("Password",password);
			
			JSONObject create = new UpdateSellerSubAccountCall().callAndGetReturnData(map1);
			int retBea = create.getInt("Code");
			boolean success = create.getBoolean("Success");
			String message = create.getString("ErrorMessage");
			
			Logger.verifyEquals(500, retBea, "Code返回结果");
			Logger.verifyEquals(false, success, "返回状态");
			Logger.verifyEquals("修改的密码长度不符合要求，请检查", message, "错误描述");

		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateSellerSubAccount_003(){
		Logger.start(true, "子账号修改 -- 子账号不存在");
		try {
			
			int sellerSubAccountUserid = 2036802500;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("SellerSubAccountUserid",sellerSubAccountUserid);
			
			JSONObject create = new UpdateSellerSubAccountCall().callAndGetReturnData(map1);
			int retBea = create.getInt("Code");
			boolean success = create.getJSONObject("Data").getBoolean("Success");
			String message = create.getJSONObject("Date").getString("ErrorMessage");
			
			
			Logger.verifyEquals(200, retBea, "返回结果等于200");
			Logger.verifyEquals(false, success, "返回状态");
			Logger.verifyEquals("子帐号不存在！", message, "错误描述");

		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateSellerSubAccount_004(){
		Logger.start(true, "子账号修改 -- 对应主账号下无该子账号");
		try {
			
			int sellerid = 425340;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("SellerId",sellerid);
			
			JSONObject create = new UpdateSellerSubAccountCall().callAndGetReturnData(map1);
			int retBea = create.getInt("Code");
			boolean success = create.getJSONObject("Data").getBoolean("Success");
			String message = create.getJSONObject("Date").getString("ErrorMessage");
			
			
			Logger.verifyEquals(200, retBea, "返回结果等于200");
			Logger.verifyEquals(false, success, "返回状态");
			Logger.verifyEquals("子帐号不存在！", message, "错误描述");

		}catch (Exception e) {
			e.printStackTrace();
		}
	}



}
